From d4ff275002c2d487ed6a424d5a661c5843a74d64 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 28 Jun 2020 23:47:26 -0400 Subject: [PATCH] node-editor: Add a help window Add a Help item to the gear menu that opens the node-format.md file in a new window. This could be improved if we could parse markdown and apply tags, similar to how we can load pango markup. --- demos/node-editor/help-window.ui | 27 ++++++++++++++++++ demos/node-editor/node-editor-application.c | 31 +++++++++++++++++++++ demos/node-editor/node-editor-window.ui | 4 +++ demos/node-editor/node-editor.gresource.xml | 2 ++ 4 files changed, 64 insertions(+) create mode 100644 demos/node-editor/help-window.ui diff --git a/demos/node-editor/help-window.ui b/demos/node-editor/help-window.ui new file mode 100644 index 0000000000..a5387393db --- /dev/null +++ b/demos/node-editor/help-window.ui @@ -0,0 +1,27 @@ + + + + + Help + 720 + 520 + + + + + word + 20 + 20 + 20 + 20 + + + + + + + + + diff --git a/demos/node-editor/node-editor-application.c b/demos/node-editor/node-editor-application.c index dd55284ca3..4a0245be8a 100644 --- a/demos/node-editor/node-editor-application.c +++ b/demos/node-editor/node-editor-application.c @@ -126,16 +126,46 @@ activate_inspector (GSimpleAction *action, gtk_window_set_interactive_debugging (TRUE); } +static void +activate_help (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + GtkBuilder *builder; + GtkWidget *window; + GtkTextBuffer *buffer; + GBytes *bytes; + const char *text; + gsize len; + + builder = gtk_builder_new (); + gtk_builder_add_from_resource (builder, "/org/gtk/gtk4/node-editor/help-window.ui", NULL); + window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); + buffer = GTK_TEXT_BUFFER (gtk_builder_get_object (builder, "buffer")); + + bytes = g_resources_lookup_data ("/org/gtk/gtk4/node-editor/node-format.md", + G_RESOURCE_LOOKUP_FLAGS_NONE, + NULL); + text = g_bytes_get_data (bytes, &len); + gtk_text_buffer_set_text (buffer, text, len); + g_bytes_unref (bytes); + + gtk_window_present (GTK_WINDOW (window)); + g_object_unref (builder); +} + static GActionEntry app_entries[] = { { "about", activate_about, NULL, NULL, NULL }, { "quit", activate_quit, NULL, NULL, NULL }, { "inspector", activate_inspector, NULL, NULL, NULL }, + { "help", activate_help, NULL, NULL, NULL }, }; static void node_editor_application_startup (GApplication *app) { + const char *help_accels[2] = { "F1", NULL }; const char *quit_accels[2] = { "Q", NULL }; const char *open_accels[2] = { "O", NULL }; GtkCssProvider *provider; @@ -145,6 +175,7 @@ node_editor_application_startup (GApplication *app) g_action_map_add_action_entries (G_ACTION_MAP (app), app_entries, G_N_ELEMENTS (app_entries), app); + gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.help", help_accels); gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.quit", quit_accels); gtk_application_set_accels_for_action (GTK_APPLICATION (app), "win.open", open_accels); diff --git a/demos/node-editor/node-editor-window.ui b/demos/node-editor/node-editor-window.ui index 1b49269ab1..791d8c0f06 100644 --- a/demos/node-editor/node-editor-window.ui +++ b/demos/node-editor/node-editor-window.ui @@ -2,6 +2,10 @@
+ + _Help + app.help + _Inspector app.inspector diff --git a/demos/node-editor/node-editor.gresource.xml b/demos/node-editor/node-editor.gresource.xml index ca6cdd2c1b..5cb5478ca3 100644 --- a/demos/node-editor/node-editor.gresource.xml +++ b/demos/node-editor/node-editor.gresource.xml @@ -2,5 +2,7 @@ node-editor-window.ui + help-window.ui + node-format.md -- 2.30.2